<?php
class IndexController extends HomeController{
    public function init(){
    }
    public function indexAction(){
        $cat_model = new CategoryModel;
        $cat_data = $cat_model->select();
        $cat_data = Datum::entree($cat_data,'id','fid','_',1);
        $art_model = new ArticleModel;
        $art_data = $art_model->order('id DESC')->limit(10)->select();
        $count = $art_model->count();

        $model = new SlideModel;
        $slide = $model->where(['status=? and sign=?'=>[1,'index']])->select();
        $this->_view->cat = $cat_data;
        $this->_view->art = $art_data;
        $this->_view->count = $count;
        $this->_view->slide = $slide;
        // var_dump($slide);
    }
    public function pageAction(){
        Yaf_Dispatcher::getInstance()->disableView();
        $page = Request::aspost(3,'page',0);
        $art_model = new ArticleModel;
        $art_data = $art_model->order('id DESC')->limit($page,10)->select();
        $data = [
            'art' => $art_data,
        ];
        $html = $this->render("page",$data);
        // var_dump($html);
        echo $html;      
    }
    public function postAction(){
        Yaf_Dispatcher::getInstance()->disableView();
        $id = Request::asget(3,'id',1);
        $art_model = new ArticleModel;
        $data = $art_model->where(['id'=>$id])->select();
    }
    public function userAction(){
        echo "index User Action";

    }
    public function testAction(){
        Yaf_Dispatcher::getInstance()->disableView();
        $model = new ArticleModel;
        var_dump($model);
        $model->count();        
    }
    public function tAction(){
        Yaf_Dispatcher::getInstance()->disableView();
        $model = new OrderInfoModel;
        $join = [
            '[>]order' => ['order_id' => 'order_id'] ,
            '[>]order_action' => ['order_id' => 'order_id']
        ];
        $columns = [
            'order.goods_name',
            'order_info.*',
            'order_action.action_user'
        ];
        $where = [
            'AND' =>['order_info.order_id' => 8]
        ];
        
        // var_dump($model->select($join,$columns,$where));
        $data = $model->join($join)->column($columns)->where($where)->select();
    }    
    public function aAction(){
        Yaf_Dispatcher::getInstance()->disableView();
        $where = ['goods_id'=>8];
        $alias = 'goods(g)';
        $join1 = [
            'order' => [0,['order_id = g.order_id'],'o'],
            'item2' => [0,['order_id' => 'order_id'],'i']

        ];
        $join = [
            // '[>]order' => 'order_id = order_id' ,
            '[>]order_action' => ['order.order_id' => 'order_id']
        ];
        $columns = [
            // 'g.goods_id',
            // 'o.order_id',
            'g' => ['goods_id','goods_name',],
            'o' => ['order_id','order_name',],
        ];
        // $this->join('left','order','alias','where');
        // var_dump(Db::table('goods')->join($join));
        // var_dump(Db::table('goods')->alias($alias));
        $com = new Command;
        // $com->alias('g')->join($join1);
        // $com->join($join1);
        // $com->where($where);
        $com->alias('g')->column($columns)->join($join1)->where($where)->select();
        // var_dump(serialize([8,9,10]));
    }
    public function hAction(){
        Yaf_Dispatcher::getInstance()->disableView();
        $model = new OrderInfoModel;
        $order = [
            '0:order' => ['order_id' => 'order_id'],
            // '0:lala:g' => [
            //     'AND' => ['name_id' => 'name_id','full_id' => 'full_id'],
            // ],
            // 'order' => ['order_id' => 'order_id','cat_id' => 'cat_id']
            // 'order' => 'order_id = order_id'
            // 'order' => ['order_id','order_id','cat_id','cat_id']
            // '1:order_action' => ['order_id' => 'order_id']

        ];
        $action = [
            'order_action' => ['order_id' => 'order_id']
        ];
        $columns = [
            'order_sn',
            // 'order.goods_name',
            // 'meta' => [
            //     'order_info.order_sn'
            // ]
            // 'order_info.order_sn',
            // 'order_action.action_user'
        ];
        $where = [
            'AND' =>['order_info.order_id' => 8]
        ];
        
        // var_dump($model->select($join,$columns,$where));
        // $data = $model->join(0,$join,'g')->column($columns)->where($where)->select();
        // $data = $model->alias('i')->join($order)->column($columns)->select();
        // $data = $model->join($order)->column($columns)->select();
        // $data = $model->join($order)->select();
        // $data = $model->select();
        // $data = $model->column($columns)->where(['city'=>52])->order(['order_id' =>'ASC'])->get();
        // $data = $model->where(['city'=>'52'])->order(['order_id' =>'DESC'])->get();
        $data = $model->where(['city'=>'52'])->get();

        var_dump($data);
    }    
}
    
